//
//  ZHBadgeView.m
//  新浪微博ZH
//
//  Created by wangzhaohui-Mac on 14-7-22.
//  Copyright (c) 2014年 com.Itheima. All rights reserved.
//

#import "WKBadgeView.h"

@implementation WKBadgeView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //设置按钮标题的字体
        self.titleLabel.font = [UIFont systemFontOfSize:11];
        //设置按钮的背景图片
        [self setBackgroundImage:[UIImage resizeImageWithName:@"main_badge"] forState:UIControlStateNormal];
    
        //设置按钮的高度就是背景图片的高度
        self.height = self.currentBackgroundImage.size.height;
    }
    return self;
}

- (void)setBadgeValue:(NSString *)badgeValue
{
    _badgeValue = [badgeValue copy];
    
    //设置文字
    [self setTitle:badgeValue forState:UIControlStateNormal];
    
    //根据文字计算自己的尺寸
    CGSize titleSize = [badgeValue sizeWithFont:self.titleLabel.font];
    CGFloat backG = self.currentBackgroundImage.size.width;
    
    if (titleSize.width < backG) {
        self.width = backG;
    }else
    {
        self.width = titleSize.width + 10;
    }
    
}

@end
